package com.coco.goods.service.impl;

import com.coco.goods.mapper.GoodsMapper;
import com.coco.goods.mapper.ItemMapper;
import com.coco.goods.pojo.TbGoods;
import com.coco.goods.pojo.TbItem;
import com.coco.goods.service.GoodsService;
import com.coco.goods.service.ItemService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 服务实现层
 * @author Administrator
 *
 */
@Service
public class ItemServiceImpl implements ItemService {

    @Autowired(required = false)
    private ItemMapper itemMapper;

    /**
     * 增加
     */
    @Override
    public void add(TbItem item) {
        itemMapper.insert(item);
    }

    /**
     * 批量删除
     */
    @Override
    public void delete(Long[] ids) {
        for(Long id:ids){
            itemMapper.deleteByPrimaryKey(id);
        }
    }

    /**
     * 修改
     */
    @Override
    public void update(TbItem item){
        itemMapper.updateByPrimaryKey(item);
    }


    /**
     * 根据ID获取实体
     * @param id
     * @return
     */
    @Override
    public TbItem findOne(Long id){
        return itemMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询全部
     */
    @Override
    public List<TbItem> findAll() {
        return itemMapper.findAll();
    }

    /**
     * 查询全部带条件
     */
    @Override
    public List<TbItem> findAll(TbItem item) {
        return itemMapper.selectByExample(item);
    }

    /**
     * 分页模糊
     */
    @Override
    public List<TbItem> findAllSearch(TbItem item) {
        PageHelper.startPage(item.getPage(),item.getLimit());
        return itemMapper.selectByExample(item);
    }
}

